package render
{
	public class NTData
	{
		private var _triples:Array;
		public function NTData(nt:String,triples:Array=null)
		{
			if(triples == null){
				_triples = new Array();
				initFromNT(nt);
			}
			else
				_triples = triples;
		}
		public function initFromRDFXML(xml:XML):void{
		}
		public function initFromNT(nt:String):void
		{
			// to remove the "\r" in unix machine
			while( nt.indexOf("\r") != -1){
				nt = nt.replace("\r","");
				trace(" find one");			
			}
			
			var lines:Array = nt.split(" .");
			
			for each(var line:String in lines){
				if(line.charAt(0) == "\n")
					line = line.substr(1);
				var verbs:Array = line.split("\t");
				
				if(verbs.length < 3)
					continue;
				
				var sub:String = verbs[0];
				var pre:String = verbs[1];
				var obj:String = verbs[2];
				
				addTriple(sub,pre,obj);
			}
		}
		
		public function addTriple(sub:String,pre:String,obj:String):void
		{
			var triple:Triple = new Triple(sub,pre,obj);
			_triples.push(triple);
			trace(" add a new triple: " + triple);
		}
		
		public function get triples():Array{
			return _triples;
		}
		public function isEmpty():Boolean{
			return _triples.length == 0;
		}
	}
}